package com.dataease.indicatorqa.controller;

import com.dataease.indicatorqa.Tools.IndicatorTools;
import com.dataease.indicatorqa.model.DatasetDetailResponse;
import com.dataease.indicatorqa.model.DatasetTreeRequest;
import com.dataease.indicatorqa.model.DatasetTreeResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "DataEase数据接口")
@RestController
@RequestMapping("/api/dataease")
@CrossOrigin
public class DataEaseController {

    @Autowired
    private IndicatorTools indicatorTools;

    @Operation(summary = "获取数据集列表")
    @PostMapping("/datasets")
    public DatasetTreeResponse getDatasets(@RequestBody(required = false) DatasetTreeRequest request) {
        // 直接调用IndicatorTools中的方法获取完整响应
        return indicatorTools.getDatasetTreeResponse();
    }

    /**
     * 获取数据集详情
     * @param datasetId 数据集ID
     * @param needAllData 是否需要完整数据，不传默认为true（展示用），传false时只返回字段元数据（AI分析用）
     * @return 数据集详情响应
     */
    @GetMapping("/dataset/detail/{datasetId}")
    public ResponseEntity<DatasetDetailResponse> getDatasetDetail(
            @PathVariable("datasetId") String datasetId,
            @RequestParam(name = "needAllData", required = false) Boolean needAllData) {

        // 如果needAllData参数未传入，默认为true（用于前端展示）
        boolean showAllData = needAllData == null || needAllData;

        DatasetDetailResponse response = indicatorTools.getDatasetDetailResponse(datasetId, showAllData);
        return ResponseEntity.ok(response);
    }

//    @Operation(summary = "获取图表数据")
//    @PostMapping("/chart/data")
//    public Map<String, Object> getChartData(@RequestBody String chartType, @RequestParam String parametersMap) {
//        // 直接调用IndicatorTools中的方法
//        return indicatorTools.getChartData(chartType, parametersMap);
//    }
}